App({
  globalData: {
    userInfo: null,
    hasUserInfo: false,
    openid: null
  },

  onLaunch() {
    // 检查登录状态
    wx.checkSession({
      success: () => {
        const openid = wx.getStorageSync('openid');
        if (openid) {
          this.globalData.openid = openid;
        } else {
          this.login();
        }
      },
      fail: () => {
        this.login();
      }
    });
  },

  async login() {
    try {
      const { code } = await wx.login();
      // 这里应该调用后端接口获取openid
      console.log('登录成功，获取到code:', code);
    } catch (err) {
      console.error('登录失败', err);
    }
  }
}); 